class VerticalLayout {
    constructor () {
        this.documentPadding = 20
        this.pageMargin = 20
    }

    computePagesSize (pageRenders) {
        return pageRenders.map(pageRender => {
            const size = pageRender.getPageShowSize()
            return {
                width: size.width,
                height: size.height,
                page: pageRender.page,
                docId: pageRender.docId
            }
        })
    }

    computedDocAndPagesRects (pageSizes) {
        const documentPadding = this.documentPadding

        let containerWidth = 0
        let containerHeight = 0
        pageSizes.forEach(pageSize => {
            const { width, height } = pageSize
          // containerWidth = Math.max(containerWidth, width + this.pageMargin * 2)
            containerWidth = Math.max(containerWidth, width)
            containerHeight = containerHeight + height + this.pageMargin
        })

        let top = documentPadding
        const pageRects = pageSizes.map(({ width, height, docId, page }) => {
            const rect = {
                width,
                height,
                top,
                left: Math.floor(containerWidth / 2 - width / 2),
                docId,
                page
            }
            top = top + height + this.pageMargin
            return rect
        })

        return {
            pageRects,
            documentSize: {
                width: containerWidth,
                height: containerHeight
            }
        }
    }
}

export { VerticalLayout }
